package br.ufla.pgcc.oomeasures.astvisitors;

import java.util.List;

import org.eclipse.jdt.core.dom.ASTVisitor;
import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jdt.core.dom.Modifier;
import org.eclipse.jdt.core.dom.Modifier.ModifierKeyword;

public class ClassInterfaceSizeVisitor extends ASTVisitor {
	private int numberOfPublicMethods;

	public ClassInterfaceSizeVisitor(){
		numberOfPublicMethods = 0;
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public boolean visit(MethodDeclaration method) {

		
		List<Modifier> modifiers = (List<Modifier>)method.modifiers();

		for (Object modifier : modifiers) {
			
			if (modifier instanceof Modifier){

				if (((Modifier)modifier).getKeyword() == ModifierKeyword.PUBLIC_KEYWORD){
					numberOfPublicMethods++;
				}
			}
		}				
		return super.visit(method);
	}

	public int getNumberOfPublicMethods(){
		return numberOfPublicMethods;
	}
} 
